/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.xinxi.dms.service;

import com.xinxi.dms.dao.RoomDao;
import com.xinxi.dms.po.Room;
import java.util.List;

/**
 *
 * @author zhigu
 */
public class RoomServiceIMPL implements IRoomService{
    RoomDao roomDao = new RoomDao();
    @Override
    public boolean add(Room room) {
        String sql = "insert into room(buildingno,unitno,roomno,money,remarks,checknumber,state,roomstate) values(?,?,?,?,?,0,?,1)";
        Object[] params = {room.getBuildingno(),room.getUnitno(),room.getRoomno(),room.getMoney(),room.getRemarks(),room.getState()};
        return roomDao.update(sql,params); 
    }
    public Room getByRoom(Room room){
        String sql = "select * from room where buildingno = ? and unitno=? "
                + "and roomno = ?";
        Object[] params = {room.getBuildingno(),room.getUnitno(),room.getRoomno()};
        return roomDao.get(sql, Room.class, params);
    }
    @Override
    public List<Room> findAll() {
        String sql = "select * from room where roomstate = 1";
        Object[] params={};
        return roomDao.query(sql, Room.class, params);
    }
    @Override
    public boolean update(Room room) {
        String sql = "update room set money = ? ,remarks = ? where roomid = ?";
        Object[] params = {room.getMoney(),room.getRemarks(),room.getRoomid()};
        return roomDao.update(sql,params);
    }
    @Override
    public boolean delete(Integer roomid ) {
        String sql ="update room set roomstate = 0 where roomid = ?";
        Object[] params={roomid };
        return roomDao.update(sql, params);
    }
    @Override
    public List<Room> getRoomUnitno(String buildingno) {
        String sql = "select distinct unitno from room where buildingno = ?";
        Object[] params={buildingno};
        return roomDao.query(sql, Room.class, params);
    }
    @Override
    public List<Room> getRoomRoomno(String buildingno, String unitno) {
        String sql = "select roomno from room where buildingno =? and unitno = ? ";
        Object[] params={buildingno,unitno};
        return roomDao.query(sql, Room.class, params);
    }
    @Override
    public List<Room> getRoom25(String unitno) {
        String sql="select roomno from room where buildingno = 25 and unitno = ?";
        Object[] params={unitno};
        return roomDao.query(sql,Room.class, params);
    }
    @Override
    public List<Room> getRoom23(String unitno) {
        String sql="select roomno from room where buildingno = 23 and unitno = ?";
        Object[] params={unitno};
        return roomDao.query(sql,Room.class, params);
    }

    @Override
    public Room getRoomid(String buildingno, String unitno, String roomno) {
        String sql="select roomid from room where buildingno = ? and unitno = ? and roomno = ?";
        Object[] params={buildingno,unitno,roomno};
        return roomDao.get(sql, Room.class, params);
    }
    
    
}
